#include "StdAfx.h"
#include "NewtonEngine.h"
#include "NewtonShapes.h"

/**
    Helper Functions for converting
*/
//float* Phys_ToArrayMatrix( const MMatrix4x4f &m )
//{
//    float f[4][4];
//    for( int i=0; i < 4; i++ )
//        for( int j=0; j < 4; j++ )
//            f[i][j] = m[i+j];
//    return &f[0][0];
//    
//}
//float* Phys_ToArrayVector3( const MVector3f &v )
//{
//    float f[3];
//}

NewtonEngine::NewtonEngine(void)
{
    m_world = 0;
}

NewtonEngine::~NewtonEngine(void)
{
}

/** Create a Shape */
IPhyShape*  NewtonEngine::CreateShape( Shape_t shape )
{
    IPhyShape* s = NULL;
    switch( shape )
    {
    case SF_BOX:
        s = new NewPhyBox( m_world );
        break;
    //case SF_SPHERE:
    //    s = new NewPhySphere( m_world );
    //    break;
    default:
        break;
    };
    return s;

}

/** Initialize */
bool NewtonEngine::Init()
{
	// create the newton world
	m_world = NewtonCreate( 0, 0 );

    return (m_world==0);
}

/** shutdown */
void NewtonEngine::Shutdown()
{
	// destroy the Newton world
	NewtonDestroy(m_world);
}

/** Update the world */
void NewtonEngine::Update( float dt )
{
	// update the Newton physics world
	NewtonUpdate( m_world, dt );
}